package com.decrypt;

import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;

public class DecryptJBoss {

    public static void main(String[] args) {
	
	
	String value=null;
	
	if(args.length <0 ) {
	    System.out.println("Necessary arguments Not passed,Please Pass the Password To Decrypt");
	}else {
	    
	    value=args[0].toString().trim();
	}
	
	//="2d7c6d39f93748e3df8592078de921bc";
	
	try {
	    System.out.println(DecryptJBoss.decode(value));    
	}catch(Exception io){
	    io.printStackTrace();
	}
	
	 
    }


public static String encode(String secret) throws NoSuchPaddingException, NoSuchAlgorithmException,  InvalidKeyException, BadPaddingException, IllegalBlockSizeException {

byte[] kbytes = "jaas is the way".getBytes();
SecretKeySpec key = new SecretKeySpec(kbytes, "Blowfish");

Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encoding = cipher.doFinal(secret.getBytes());
BigInteger n = new BigInteger(encoding);
return n.toString(16);
}

public static char[] decode(String secret) throws NoSuchPaddingException, NoSuchAlgorithmException,  InvalidKeyException, BadPaddingException, IllegalBlockSizeException {

byte[] kbytes = "jaas is the way".getBytes();
SecretKeySpec key = new SecretKeySpec(kbytes, "Blowfish");

BigInteger n = new BigInteger(secret, 16);
byte[] encoding = n.toByteArray();

Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] decode = cipher.doFinal(encoding);
return new String(decode).toCharArray();

  }


}
